﻿using System;
using System.Collections.Generic;

namespace ProblemsSet
{
    public class Problem_62 : BaseProblem
    {
        public override object GetResult()
        {
            var cnt = 2;
            while(true)
            {
                cnt++;
                long min = (long)Math.Pow(10, (double)cnt/3);
                long max = (long)Math.Pow(10, (double)(cnt+1)/3);

                var dct = new Dictionary<string, List<long>>();

                for (long tst = min; tst <= max; tst++)
                {
                    var tmp = MathLogic.GetHashOfDigits(tst*tst*tst);
                    if (!dct.ContainsKey(tmp)) dct.Add(tmp, new List<long>());
                    dct[tmp].Add(tst);
                }
                foreach (var pair in dct)
                {
                    if (pair.Value.Count == 5)
                    {
                        long mn = int.MaxValue;
                        foreach (var l in pair.Value)
                        {
                            if (l < mn) mn = l;
                        }
                        return mn*mn*mn;
                    }
                }
            }
            return -1;
        }

        public override string Problem
        {
            get
            {
                return @"The cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest cube which has exactly three permutations of its digits which are also cube.

Find the smallest cube for which exactly five permutations of its digits are cube.";
            }
        }

        public override bool IsSolved
        {
            get
            {
                return true;
            }
        }

        public override object Answer
        {
            get
            {
                return 127035954683;
            }
        }
    }
}
